package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CategoryMapper {
    //新增分类
    @Insert("insert into category values(null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer addCategory(Category category);

    //根据分类名查询
    @Select("select * from category where `name`=#{name} ")
    Category selectCategory(Category category);

    /**
     * 使用pagehelper进行分页查询
     * @param
     * @return
     */
    @Select("select * from category")
    List<Category> selectAll();

    /**
     * 删除分类
     * @param id
     * @return
     */
    @Delete("delete from category where id=#{id}")
    Integer delete(Long id);

    /**
     * 修改分类
     * @param category
     * @return
     */
//    @Update("update category set `type`=#{type},`name`=#{name},sort=#{sort},create_time=#{createTime},update_time=#{updateTime},create_user=#{createUser},update_user=#{updateUser} where id=#{id}")
    Integer update(Category category);

    /**
     * 根据名字查询分类
     * @param name
     * @return
     */
    @Select("select * from category where name=#{name}")
    Category selectByName(String name);


    /**
     * 根据类型获取菜品分类
     * @param type
     * @return
     */
    List<Category> selectByType(Integer type);

    /**
     * 根据categoryId查找分类
     * @param id
     * @return
     */
    @Select("select * from category where id=#{id}")
    Category findCategoryById(Long id);


}
